/**
 * @version 3 11 February 2013
 * @author Myhaylo Kotsyuruba
 */

public class YesNoQuestions extends Question{

    private static final int CODE_TRUE_ANSWER = 1;
    
    private boolean answer;
    
    public YesNoQuestions(String text,int score, boolean answer) {
        super(text, score);
        this.answer = answer;
    }

    @Override
    public YesNoQuestions clone() {
        return new YesNoQuestions(getText(), getScore(), answer);
    }

    @Override
    public AnswerMap convertsUserAnswer(String userAnswer) {
        String markingTrue = "Y";
        AnswerMap userAnswerMap = new AnswerMap(1);
        if (userAnswer.equalsIgnoreCase(markingTrue)) {
            userAnswerMap.setField(0, CODE_TRUE_ANSWER);
        }
        return userAnswerMap;
    }

    @Override
    public AnswerMap getCorrectAnswerMap() {
        AnswerMap correctAnswerMap = new AnswerMap(1);
        if (answer == true) {
            correctAnswerMap.setField(0, CODE_TRUE_ANSWER);
        }
        return correctAnswerMap;
    }
    
    @Override
    public String toString() {
        String result = String.format("%s%nPlease, type `Y` or `N`.",
                getText());
        return result;
    }
}
